package com.example.musicplayer;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView menu1;
    private TextView menu2;
    private FragmentManager fm;
    private FragmentTransaction ft;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        fm = getSupportFragmentManager();
        ft = fm.beginTransaction();
        ft.replace(R.id.content, new Frag1());
        ft.commit();
    }

    @Override
    public void onClick(View view) {
        ft = fm.beginTransaction();
        switch (view.getId()) {
            case R.id.menu1:
                ft.replace(R.id.content, new Frag1());
                break;
            case R.id.menu2:
                ft.replace(R.id.content, new Frag2());
                break;
        }
        ft.commit();
    }

    private void initView() {
        menu1 = (TextView) findViewById(R.id.menu1);
        menu2 = (TextView) findViewById(R.id.menu2);

        menu1.setOnClickListener(this::onClick);
        menu2.setOnClickListener(this::onClick);
    }
}